module.exports = function(grunt) {
    
    var completeSrcPath = function(cssSrcPaths, relPath){
        var srcPaths = [];
        relPath = relPath || '../css/';
        //补全javascript文件路径.
        for(var i=0, len=cssSrcPaths.length; i<len; i++){
            srcPaths[i] = relPath + cssSrcPaths[i];
        }
        return srcPaths;
    };
    
    //-------------------------------------------------------------------------------------
    
    //获取UJS子模块的路径提取器.
    var cssGetter = require('./resource_path/css_res.js'),
        cssCorePaths = cssGetter.getResPath(),
        cssAllPaths = cssGetter.getResPath({
            component : true,
            jqueryPlugins : true
        });
        
    //App resource.
    
    var imCssGetter = require('./resource_path/app/im/css_res.js'),
        imCssPaths = imCssGetter.getResPath();
    
    var pageDesignerCssGetter = require('./resource_path/app/pageDesigner/css_res.js'),
        pageDesignerCssPaths = pageDesignerCssGetter.getResPath();
        
    // Project configuration.
    grunt.initConfig({
        pkg : grunt.file.readJSON('package.json'),        
        css_url_replace: {
            task : {
                options: {
                    staticRoot: 'acucom'
                },
                files: {
                    '../build/<%= pkg.name %>.core.debug.css' : completeSrcPath(cssCorePaths),
                    '../build/<%= pkg.name %>.debug.css' : completeSrcPath(cssAllPaths),
                    
                    '../build/app/im/im.debug.css' : completeSrcPath(imCssPaths, '../app/im/css/'),
                    '../build/app/pageDesigner/pageDesigner.debug.css' : completeSrcPath(pageDesignerCssPaths, '../app/pageDesigner/css/')
                }
            }
        },
        cssmin: {        
            combine: {
                files: {
                    '../build/<%= pkg.name %>.core.min.css': [ '../build/<%= pkg.name %>.core.debug.css' ],
                    '../build/<%= pkg.name %>.min.css': [ '../build/<%= pkg.name %>.debug.css' ],
                    
                    '../build/app/im/im.min.css' : [ '../build/app/im/im.debug.css' ],
                    '../build/app/pageDesigner/pageDesigner.min.css' : [ '../build/app/pageDesigner/pageDesigner.debug.css' ]
                }
            }
        }    
    });
    
    require('./../../tools/grunt/node_modules/grunt-contrib-cssmin/tasks/cssmin.js')(grunt);
    require('./../../tools/grunt/node_modules/grunt-css-url-replace/tasks/css_url_replace.js')(grunt);
    
    // Default task(s).
    grunt.registerTask('default', ['css_url_replace', 'cssmin']);
}; 